import axios from '@/api/fetch';
import SERVER from '@/api/server';

export const queryPartInfos = params => axios.get(`${SERVER.DMSCLOUD_PART}/basedata/partInfos`, { params });

export const addPartInfo = params => axios.put(`${SERVER.DMSCLOUD_PART}/basedata/partInfos`, params);

export const getPartInfo = partNOs => axios.get(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/getPartInfo?partNOs=${partNOs}`);

export const updatePartInfoByPartNos = params => axios.post(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/updatePartInfoByPartNos`, params);

export const queryPartInfo = params => axios.get(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/queryPartInfo`, { params });

export const savePartAdjustment = params => axios.post(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/savePartAdjustment`, params);

export const ModifyPartInfo = (params, id) => axios.post(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/a?id=${id}`, params);

export const queryUnitCode = params => axios.get(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/partGroupCode`, { params });

export const queryModel = params => axios.get(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/partModel`, { params });

// 获取所有品牌
export const getBrandAll = params => axios.get(`${SERVER.DMSCLOUD_SYSBASEDATA}/basedata/vehicleProduct/brandsqueryall`, {});
// 获取包装单位
export const queryPackUnit = params => axios.get(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/partGroupCode`, {});
// 获取库位模板
export const modelDownload = params => {
  const url = `${SERVER.DMSCLOUD_PART}/basedata/LibraryDefinition/download`;
  return axios({
    url,
    method: 'get',
    responseType: 'blob'
  });
};
// 获取所有车型
export const getAllModel = params => axios.get(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/getAllModel`);
// 获取包装单位
// export const partExport = params => axios.get(`${SERVER.DMSCLOUD_PART}/basedata/partInfos/export`, { params });
export const partExport = (params = {}) => {
  for (const key in params) {
    if (!params[key]) {
      params[key] = '';
    }
  }
  const url =
    `${SERVER.DMSCLOUD_PART}/basedata/partInfos/export` +
    '?limit=100000&pageNum=' +
    params.pageNum +
    '&brand=' +
    params.brand +
    '&partNo=' +
    params.partNo +
    '&partName=' +
    params.partName +
    '&oemTag=' +
    params.oemTag +
    '&isAccessory=' +
    params.isAccessory +
    '&remark=' +
    params.remark +
    '&begin=' +
    params.begin +
    '&end=' +
    params.end;
  return axios({
    url,
    method: 'get',
    responseType: 'blob'
  });
};
